// pages/bulletin/index/index.js
var app = getApp();
var utils=require('../../utils/util.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    codeTxt: "",
    dataList: [],
    curPage:1,
    pageCount:10,
    pageSize: 10,
    rowCount: 0,
    hasMoreData: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     var that = this;
     var curPage = that.data.curPage;
     console.log(wx.getStorageSync("busId"))
     console.log(wx.getStorageSync("employeesId"))
     console.log(wx.getStorageSync("schoolId"))
     wx.request({
      url: app.globalData.http + "noticeList.do",
      header: {
        'content-type': 'application/json'
      },
      data: {
        curPage : curPage,
        busId: parseInt(wx.getStorageSync("busId")),
        employeesId: parseInt(wx.getStorageSync("employeesId")),
        schoolId: parseInt(wx.getStorageSync("schoolId"))
       
      },
      method:"GET",
      success: function(res){
        console.log(res.data);
        var code = res.data.code;
        if(code == 100){
            var subList = res.data.data.subList;
            var length = res.data.data.subList.length;
            for(var i = 0; i < length; i++){
              res.data.data.subList[i].updateDate =utils.formatTime( new Date(res.data.data.subList[i].updateDate));
              //console.log(res.data.data.subList[i].updateDate);
            }
            that.setData({
              dataList: res.data.data.subList,
              curPage: curPage+1,
              pageCount: res.data.data.pageCount
            });
            console.log("curpage===",that.data.curPage);
        }
        if(code == 200){
          that.setData({
            codeTxt: "暂时没有数据"
          })
        }
        if(code == 300){
          that.setData({
            codeTxt: "对不起 接口异常"
          })
        }
      
      }

    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */

  onReachBottom: function () {
    var that = this;
    var hasMoreData = that.data.hasMoreData;
    var url = app.globalData.http + "noticeList.do";
    console.log("curpage===",that.data.curPage);
    utils.loadMore(that,hasMoreData,url)  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})